package com.example.projectcode.controller.Student;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.projectcode.model.Kdpoints;
import com.example.projectcode.model.Subject;
import com.example.projectcode.result.Result;
import com.example.projectcode.service.KdpointsService;
import com.example.projectcode.service.SubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "各科考试重难点查看接口")
@RestController
@RequestMapping("/user/viewKdpoints")
public class ViewKdpointsController {

    @Autowired
    private KdpointsService kdpointsService;

    @Autowired
    private SubjectService subjectService;

    @ApiOperation("显示所有科目")
    @GetMapping(value = "/displayAllSubjects")
    public Result displayAllSubjects(){
        List<Subject> subjectList = new ArrayList<>();
        subjectList = subjectService.selectAllSubject();
        return Result.ok(subjectList);

    }

    @ApiOperation("根据科目id查看科目的考试重难点")
    @GetMapping("/displayKdpoints/{subid}")
    public  Result displayKdpoints(@PathVariable Integer subid){
        List<Kdpoints> kdpointsList = new ArrayList<>();
        kdpointsList = kdpointsService.selectAllKdpoints(subid);
        Map<String,Object> map = new HashMap<>();
        Subject subject = subjectService.selectSubjectBySubId(subid);
        map.put(subject.getSubname(),kdpointsList);
        return Result.ok(map);

    }


    /*---------------------------新加--------------------------------------*/

    @ApiOperation("分页查询所有科目")
    @GetMapping("/queryAllSubject/{page}/{size}")
    public Result queryAllSUbject(@PathVariable long page,@PathVariable long size){
        Page<Subject> subjectPage = new Page<>(page,size);

        IPage<Subject> subjectIPage = subjectService.page(subjectPage,null);
        return Result.ok(subjectIPage);
    }





    @ApiOperation("根据科目id分页查询所有重难点信息")
    @GetMapping("/queryAllKPoints/{subId}/{page}/{size}")
    public Result queryAllKPoints(@PathVariable Integer subId,@PathVariable long page, @PathVariable long size){
        Page<Kdpoints> kdpointsPage = new Page<>(page,size);
        IPage<Kdpoints> kdpointsIPage = kdpointsService.page(kdpointsPage,
                new QueryWrapper<Kdpoints>().eq("Subid",subId));
        return Result.ok(kdpointsIPage);
    }


}
